/**
 * 功能描述
 */
define(function (require, exports, module) {
	var Grid = require("grid");
	var aw = require("ajaxwrapper");
	var Dialog = require("dialog");
	var tools = require("tools");
	
    var instance = {
        initComponent: function (params, widget) {
        	var grid = new Grid({
        		parentNode : ".J-grid",
        		autoRender: false,
        		model : {
        			url : "api/checkinmeeting/queryall",
            		params : function(){
            			var subnav = widget.get("subnav");
            			return {
            				"checkInImplement.servicePoint.pkServicePoint": subnav.getValue("servicePoint"),
            				"status": subnav.getValue("status"), 
            				startDate : subnav.getValue("startDate").start,
            				endDate : subnav.getValue("startDate").end,
            				fetchProperties:"*,checkInImplement.version," +
							"checkInImplement.pkCIImplement," +
							"checkInImplement.status," +
							"checkInImplement.signUpNum," +
							"checkInImplement.dataSource.*," +
							"status.*," +
							"checkInImplement.groupReserve.*," +
							"checkInImplement.groupReserve.planItemGroup.allianceOrg.*," +
							"checkInImplement.groupReserve.planItemGroup.planItem.*," +
							"checkInImplement.groupReserve.planItemGroup.planItem.destination.*," +
							"checkInImplement.groupReserve.planItemGroup.servicePoint.pkServicePoint," +
							"checkInImplement.groupReserve.planItemGroup.servicePoint.name," +
							"checkInImplement.groupReserve.planItemGroup.signUps.version," +
							"checkInImplement.nonMemGroupReserve.nonMemberGroup.*," +
							"checkInImplement.nonMemGroupReserve.nonMemberGroup.groupUnit," +
							"checkInImplement.nonMemGroupReserve.nonMemberGroup.servicePoint.name," +
							"checkInImplement.nonMemGroupReserve.nonMemberGroup.signUpType.*," +
							"checkInImplement.nonMemGroupReserve.nonMemberGroup.operator.servicePoint.name," +
							"checkInImplement.nonMemGroupReserve.nonMemberGroup.signUps.version"
            			}
            		},
        			columns : [{
                    	name : "group",
                    	label : "团/散客",
                    	format : function(value, row){
                    		if(row.checkInImplement.dataSource.key == "GroupReserve"){
        						return "老人团";
        					}else{
        						return "散客";
        					}
                    	}
                    },{
                    	name:"checkInImplement.groupReserve",
        				label:"组团单位/预约人",
        				format: function(value,row){
        					if(row.checkInImplement.dataSource.key == "GroupReserve"){
        						if(value.planItemGroup.allianceOrg){
        							return value.planItemGroup.allianceOrg.name;
        						}else{
        							return value.planItemGroup.servicePoint.name
        						}
        					}else{
    							return row.checkInImplement.nonMemGroupReserve.nonMemberGroup.contactName;
        					}
        				}
        			},{
        				name:"checkInImplement.groupReserve.planItemGroup.planItem.destination.name",
        				label:"目的地",
        				format : function(value, row){
        					if(row.checkInImplement.dataSource.key == "GroupReserve"){
        						return value;
        					}else{
        						return row.checkInImplement.nonMemGroupReserve.nonMemberGroup.servicePoint.name;
        					}
        				}
					},{
						name:"checkInImplement.groupReserve.checkInDate",
						label:"入住日期",
						format: function(value, row){
							if(row.checkInImplement.dataSource.key == "GroupReserve"){
        						return moment(value).format("YYYY-MM-DD");
        					}else{
        						return moment(row.checkInImplement.nonMemGroupReserve.nonMemberGroup.checkInDate).format("YYYY-MM-DD");
        					}
						}
					},{						
						name:"checkInImplement.groupReserve.checkOutDate",
        				label:"退住日期",
        				format:function(value,row){
        					if(row.checkInImplement.dataSource.key == "GroupReserve"){
        						return moment(value).format("YYYY-MM-DD");
        					}else{
        						return moment(row.checkInImplement.nonMemGroupReserve.nonMemberGroup.checkOutDate).format("YYYY-MM-DD");
        					}
        				}
					},{
        				name:"meetingDate",
        				label:"会议时间",
        				format:function(value,row){
        					return moment(value).format("YYYY-MM-DD HH:mm:SS");
        				}
        			},{
        				name:"meetingRoom",
        				label:"会议室"
        			},{
        				name:"peoCount",
        				label:"参会人数"
        			},{
        				name:"checkInImplement.signUpNum",
        				label:"报名人数"
        			},{
						name:"status.value",
						label:"状态"
					},{
						name:"operate",
						label:"操作",
						format:"button",
						formatparams:[{
							key:"edit",
							text:"落实",
							show:function(value,data){
								if (data.status.key == "Pending") {
									return true;
			                    } else {
			                        return false;
			                    }
							},
							handler:function(index,data,rowEle){
								
	        						if(data.checkInImplement.status.key=="Edited" || data.checkInImplement.status.key=="Initial"){
	        							Dialog.alert({
						    				content:"此数据未准备，不得落实！"
						            	});
	        						}else{
	        							var form = widget.get("form");
	    								widget.show([".J-form"]).hide([".J-grid"]);
	    								widget.get("subnav").show(["return"]).hide(["search","status","servicePoint","startDate"]);
	    								form.reset();
	    								form.setValue("meetingDate", data.meetingDate);
	    								form.setValue("screenings", data.screenings);
	    								form.setValue("pkCheckInMeeting", data.pkCheckInMeeting);
	    								form.setValue("version", data.version);
	    								form.setValue("meetingRoom", data.meetingRoom);
	    								form.setValue("peoCount", data.peoCount);
	    								form.setValue("meetPlaceType", data.meetPlaceType);
	    								form.setValue("content", data.content);
	    								form.setValue("contentLED", data.contentLED);
	    								form.setValue("license", data.license);
	    								form.setValue("checkInImplement", data.checkInImplement.pkCIImplement);
	        						}
							}	
						}]
					}]
        		}
        	});
        	widget.set("grid", grid);
        }
    };
    module.exports = instance;
});
